package com.jxl.dnd.charactercreator.vo
{
	[Bindable]
	public class CharacterSheetVO
	{
		
		public var name:String;
		public var character:Character;
		public var majorVersion:uint 				= 1;
		public var minorVersion:uint				= 0;
		
		public function CharacterSheetVO():void
		{
			super();
			this.name			= "Default Character Sheet";
			this.character		= new Character();
		}

		public function buildFromObject(obj:Object):void
		{
			this.name				= obj.name;
			this.character			= new Character();
			this.character.buildFromObject(obj.character);
			this.majorVersion		= obj.majorVersion;
			this.minorVersion		= obj.minorVersion;
		}
		
		public function toObject():Object
		{
			var obj:Object 		= new Object();
			obj.name			= name;
			obj.character		= character.toObject();
			obj.majorVersion	= majorVersion;
			obj.minorVersion	= minorVersion;
			return obj;
		}
		
		public function toXML():String
		{
			var myXML:XML = 
				<charactersheet>
					<name>{name}</name>
					<majorversion>{majorVersion}</majorversion>
					<minorversion>{minorVersion}</minorversion>
				</charactersheet>;
			if(character != null) myXML.appendChild(character.toXML());
			return myXML;
		}
		
		public function buildFromXML(xml:XML):void
		{
			name				= xml.name;
			majorVersion		= xml.majorVersion;
			minorVersion		= xml.minorVersion;
			character			= new Character();
			character.buildFromXML(xml);
		}
	}
}